package com.tiza.xiaoyoubao.ui.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.squareup.picasso.Picasso;
import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.Constants;
import com.tiza.xiaoyoubao.app.UIHelper;
import com.tiza.xiaoyoubao.entity.AdvancesCompleteInfo;
import com.tiza.xiaoyoubao.entity.InsertTaskInfo;
import com.tiza.xiaoyoubao.entity.MpTmTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.SeclectDianFuReceiveInfo;
import com.tiza.xiaoyoubao.entity.SeclectDianFuThreeInfo;
import com.tiza.xiaoyoubao.entity.SeclectDianFuTwoInfo;
import com.tiza.xiaoyoubao.entity.TaskAllInfo;
import com.tiza.xiaoyoubao.entity.TaskOperateInfo;
import com.tiza.xiaoyoubao.entity.TaskRebatesInfo;
import com.tiza.xiaoyoubao.entity.TaskShipMentsInfo;
import com.tiza.xiaoyoubao.entity.UserInfo;
import com.tiza.xiaoyoubao.entity.bean.BankInfo;
import com.tiza.xiaoyoubao.net.ApiHttpClient;
import com.tiza.xiaoyoubao.net.JsonCallback;
import com.tiza.xiaoyoubao.net.ResponseInfo;
import com.tiza.xiaoyoubao.utils.DateUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by mapple on 17/5/22.
 * 手机天猫任务2
 */

public class MpTmTask2Fragment extends BaseFragment {
    @BindView(R.id.iv1)
    ImageView iv1;
    @BindView(R.id.iv2)
    ImageView iv2;
    @BindView(R.id.iv3)
    ImageView iv3;
    @BindView(R.id.iv4)
    ImageView iv4;
    @BindView(R.id.iv5)
    ImageView iv5;
    @BindView(R.id.iv6)
    ImageView iv6;
    @BindView(R.id.iv7)
    ImageView iv7;
    @BindView(R.id.iv8)
    ImageView iv8;
    @BindView(R.id.iv9)
    ImageView iv9;
    @BindView(R.id.iv10)
    ImageView iv10;
    @BindView(R.id.iv11)
    ImageView iv11;
    @BindView(R.id.iv12)
    ImageView iv12;
    @BindView(R.id.iv13)
    ImageView iv13;
    @BindView(R.id.view_FuJia)
    View view_FuJia;
    @BindView(R.id.iv_evaluation1)
    ImageView iv_evaluation1;
    @BindView(R.id.iv_evaluation2)
    ImageView iv_evaluation2;
    @BindView(R.id.iv_image)
    ImageView iv_image;
    @BindView(R.id.iv_goRight)
    ImageView iv_goRight;
    //商户ID
    @BindView(R.id.tv_sellerId)
    TextView tv_sellerId;
    //类型
    @BindView(R.id.tv_backType)
    TextView tv_backType;
    //价格
    @BindView(R.id.tv_cJPrice)
    TextView tv_cJPrice;
    //数量
    @BindView(R.id.tv_num)
    TextView tv_num;
    //任务状态
    @BindView(R.id.tv_taskState)
    TextView tv_taskState;
    //商家要求
    @BindView(R.id.tv_sellerRequire)
    TextView tv_sellerRequire;
    //订单留言
    @BindView(R.id.tv_message)
    TextView tv_message;
    //时间
    @BindView(R.id.tv_time)
    TextView tv_time;
    //任务编号
    @BindView(R.id.tv_taskId)
    TextView tv_taskId;
    //买号
    @BindView(R.id.tv_buyerId)
    TextView tv_buyerId;
    //商品金额
    @BindView(R.id.tv_price)
    TextView tv_price;
    //获得佣金
    @BindView(R.id.tv_getCommission)
    TextView tv_getCommission;
    //订单付款状态
    @BindView(R.id.tv_state)
    TextView tv_state;
    //商家确认订单状态
    @BindView(R.id.tv_sellerState)
    TextView tv_sellerState;
    //收货好评状态
    @BindView(R.id.tv_evaluationState)
    TextView tv_evaluationState;
    //任务完成状态
    @BindView(R.id.tv_taskCompleteState)
    TextView tv_taskCompleteState;
    //倒计时
    @BindView(R.id.tv_countDwon)
    TextView tv_countDwon;
    @BindView(R.id.tv_rebatesWay)
    TextView tv_rebatesWay;
    @BindView(R.id.tv_rebatesAccount)
    TextView tv_rebatesAccount;
    @BindView(R.id.tv_rebatesMoney)
    TextView tv_rebatesMoney;

    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.view3)
    View view3;
    @BindView(R.id.view4)
    View view4;
    @BindView(R.id.iv_2)
    ImageView iv_2;
    @BindView(R.id.iv_3)
    ImageView iv_3;
    @BindView(R.id.iv_4)
    ImageView iv_4;
    @BindView(R.id.iv_5)
    ImageView iv_5;
    @BindView(R.id.bt_operationTask)
    Button bt_operationTask;
    @BindView(R.id.bt_CancelTask)
    Button bt_CancelTask;
    @BindView(R.id.bt_complaintTask)
    Button bt_complaintTask;
    @BindView(R.id.btn_pushRebates)
    Button btn_pushRebates;
    @BindView(R.id.btn_shouHuo)
    Button btn_shouHuo;
    private AdvancesCompleteInfo advancesCompleteInfo;
    private TaskOperateInfo taskOperateInfo;
    private TaskRebatesInfo taskRebatesInfo;
    private TaskShipMentsInfo taskShipMentsInfo;
    private MpTmTaskOrderInfo mpTmTaskOrderInfo;
    private TaskAllInfo taskAllInfo;
    InsertTaskInfo mInsertTaskInfo = Hawk.get(Constants.KEY_INSERTTASK_INFO, (InsertTaskInfo) null);
    UserInfo userInfo = Hawk.get(Constants.KEY_USER_INFO, (UserInfo) null);

    Bundle args;
    private String state, cid, taskTime, orderid, buyerid, taskCode, reason, account, sellerID;
    private boolean isOverTime = false;
    Timer timer = new Timer();
    DateFormat df;
    Date date1;
    Date date2;
    long diff;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        args = getArguments();
        state = args.getString("state");
    }
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mp_tm_task2;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        switch (state) {
            case "AdvancesComplate":
                AdvancesComplate();
                break;
            case "operate":
                Operate();
                break;
            case "rebates":
                Rebates();
                break;
            case "shipments":
                Shipments();
                break;
            case "orderTask":
                OrderTask();
                break;
            case "allTask":
                AllTask();
                break;
            default:
                break;
        }

    }


    @OnClick({
            R.id.view_go,
            R.id.bt_operationTask,
            R.id.bt_complaintTask,
            R.id.bt_CancelTask,
            R.id.btn_pushRebates,
            R.id.btn_shouHuo
    })
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.view_go:
                UIHelper.showMpTMTaskDetail2(mActivity, args);
                break;
            case R.id.bt_operationTask:
                if (isOverTime) {
                    toast("任务已超时，无法进行操作");
                } else {
                    if (state.equals("operate")) {
                        args.putString("way", "2");
                        args.putSerializable("info", taskOperateInfo);
                    } else if (state.equals("orderTask")) {
                        args.putString("way", "1");
                    }
                    UIHelper.showMpTMOperationTask(mActivity, args);
                    finish();
                }
                break;
            case R.id.bt_complaintTask:
                UIHelper.showComplain(mActivity);
                finish();
                break;
            case R.id.bt_CancelTask:
                if (state.equals("operate")) {
                    args.putString("way", "2");
                    args.putSerializable("info", taskOperateInfo);
                } else if (state.equals("orderTask")) {
                    args.putString("way", "1");
                }
                UIHelper.showCancleTask(mActivity, args);
                //finish();
                break;
            case R.id.btn_pushRebates:
                break;
            case R.id.btn_shouHuo:
                AlertDialog.Builder builder1 = new AlertDialog.Builder(getContext());
                builder1.setTitle("提示");
                builder1.setMessage("务必确认物流信息已显示签收,且距离付款时间至少满3天");
                builder1.setPositiveButton("是", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 隐藏当前对话框
                        Bundle args = new Bundle();
                        args.putString("type","taobaoTask");
                        args.putSerializable("info", taskShipMentsInfo);
                        UIHelper.showEva(mActivity, args);
                        dialog.dismiss();
                        finish();
                    }
                });

                builder1.setNegativeButton("否", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 隐藏当前对话框
                        dialog.dismiss();
                    }
                });

                builder1.create().show();
                break;
            default:
                break;
        }
    }



    public void AdvancesComplate() {
        bt_operationTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_operationTask.setEnabled(false);
        bt_CancelTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_CancelTask.setEnabled(false);
        btn_pushRebates.setBackgroundResource(R.mipmap.rwxq_cfk_no);
        btn_pushRebates.setEnabled(false);
        bt_complaintTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_complaintTask.setEnabled(false);
        advancesCompleteInfo = (AdvancesCompleteInfo) args.getSerializable("info");
        tv_taskId.setText(advancesCompleteInfo.getOrderid());
        tv_buyerId.setText(advancesCompleteInfo.getAccount());
        tv_sellerId.setText("商家ID:" + advancesCompleteInfo.getUserId());
        tv_backType.setText(advancesCompleteInfo.getBackName());
        tv_cJPrice.setText(advancesCompleteInfo.getPrice());
        tv_num.setText(advancesCompleteInfo.getNumber() + "件");
        tv_time.setText(DateUtils.getDateToStringSec(advancesCompleteInfo.getAddTime()));
        tv_price.setText(advancesCompleteInfo.getMobilePrice());
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + advancesCompleteInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_taskState.setText("任务状态：已完成");
        tv_state.setText("已完成");
        tv_sellerState.setText("已完成");
        tv_evaluationState.setText("已完成");
        tv_taskCompleteState.setText("已完成");
        if (advancesCompleteInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + advancesCompleteInfo.getRemarks());
        }
        if (TextUtils.isEmpty(advancesCompleteInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + advancesCompleteInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(advancesCompleteInfo.getBaseCmi()));
        view2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view3.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view4.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        iv_2.setImageResource(R.mipmap.rwxq_2);
        iv_3.setImageResource(R.mipmap.rwxq_3);
        iv_4.setImageResource(R.mipmap.rwxq_4);
        iv_5.setImageResource(R.mipmap.rwxq_5);
    }

    /**
     * 待操作
     */
    public void Operate() {
        tv_countDwon.setVisibility(View.VISIBLE);
        taskOperateInfo = (TaskOperateInfo) args.getSerializable("info");
        tv_taskId.setText(taskOperateInfo.getOrderid());
        tv_buyerId.setText(taskOperateInfo.getAccount());
        tv_sellerId.setText("商家ID:" + taskOperateInfo.getUserId());
        tv_backType.setText(taskOperateInfo.getBackName());
        tv_cJPrice.setText(taskOperateInfo.getPrice());
        tv_num.setText(taskOperateInfo.getNumber() + "件");
        tv_time.setText(DateUtils.getDateToStringSec(taskOperateInfo.getAddTime()));
        tv_price.setText(taskOperateInfo.getMobilePrice());
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + taskOperateInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_taskState.setText("任务状态：待操作");
        tv_state.setText("未完成");
        tv_sellerState.setText("未完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (taskOperateInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + taskOperateInfo.getRemarks());
        }
        if (TextUtils.isEmpty(taskOperateInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + taskOperateInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(taskOperateInfo.getBaseCmi()));
        taskTime = DateUtils.getDateToStringSec(taskOperateInfo.getEndTime());
        cid = String.valueOf(taskOperateInfo.getId());
        orderid = taskOperateInfo.getOrderid();
        //TODO(待测)
        buyerid = taskOperateInfo.getUserId();
        taskCode = taskOperateInfo.getTaskCode();
        account = taskOperateInfo.getAccount();
        sellerID = taskOperateInfo.getSellerId();
        df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        timer.schedule(task, 1000, 1000);
    }

    /**
     * 待操作(订单任务)
     */
    public void OrderTask() {
        tv_countDwon.setVisibility(View.VISIBLE);
        mpTmTaskOrderInfo = (MpTmTaskOrderInfo) args.getSerializable("info");
        tv_taskId.setText(mInsertTaskInfo.getOrderid());
        tv_buyerId.setText(mInsertTaskInfo.getBuyerid());
        tv_sellerId.setText("商家ID:" + mpTmTaskOrderInfo.getUserId());
        tv_backType.setText(mpTmTaskOrderInfo.getBackName());
        tv_cJPrice.setText(mpTmTaskOrderInfo.getPrice());
        tv_num.setText(mpTmTaskOrderInfo.getNumber() + "件");
        tv_taskState.setText("任务状态：待操作");
        tv_time.setText(DateUtils.getDateToStringSec(mInsertTaskInfo.getAddtime()));
        tv_price.setText(mpTmTaskOrderInfo.getMobilePrice());
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + mpTmTaskOrderInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_state.setText("未完成");
        tv_sellerState.setText("未完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (mpTmTaskOrderInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + mpTmTaskOrderInfo.getRemarks());
        }
        if (TextUtils.isEmpty(mpTmTaskOrderInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + mpTmTaskOrderInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(mpTmTaskOrderInfo.getBaseCmi()));
        taskTime = DateUtils.getDateToStringSec(mInsertTaskInfo.getEndtime());
        cid = String.valueOf(mInsertTaskInfo.getCid());
        orderid = mInsertTaskInfo.getOrderid();
        buyerid = mInsertTaskInfo.getBuyerid();
        taskCode = mInsertTaskInfo.getTaskCode();
        account = mInsertTaskInfo.getAccount();
        sellerID = mInsertTaskInfo.getSellerid();
        df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        timer.schedule(task, 1000, 1000);
    }

    /**
     * 待返款
     */
    public void Rebates() {
        getBankInfo();
        bt_operationTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_operationTask.setEnabled(false);
        bt_CancelTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_CancelTask.setEnabled(false);
        taskRebatesInfo = (TaskRebatesInfo) args.getSerializable("info");
        orderid = taskRebatesInfo.getOrderid();
        selectDianfuTwo();
        tv_taskId.setText(taskRebatesInfo.getOrderid());
        tv_buyerId.setText(taskRebatesInfo.getAccount());
        tv_sellerId.setText("商家ID:" + taskRebatesInfo.getUserId());
        tv_backType.setText(taskRebatesInfo.getBackName());
        tv_cJPrice.setText(taskRebatesInfo.getPrice());
        tv_num.setText(taskRebatesInfo.getNumber() + "件");
        tv_time.setText(DateUtils.getDateToStringSec(taskRebatesInfo.getAddTime()));
        tv_price.setText(taskRebatesInfo.getMobilePrice());
        tv_rebatesWay.setText(taskRebatesInfo.getBackName());
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + taskRebatesInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_taskState.setText("任务状态：待返款");
        tv_state.setText("已完成");
        tv_sellerState.setText("未完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (taskRebatesInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + taskRebatesInfo.getRemarks());
        }
        if (TextUtils.isEmpty(taskRebatesInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + taskRebatesInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(taskRebatesInfo.getBaseCmi()));
        view2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        iv_2.setImageResource(R.mipmap.rwxq_2);
    }

    /**
     * 发货中
     */
    public void Shipments() {
        bt_operationTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_operationTask.setEnabled(false);
        bt_CancelTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_CancelTask.setEnabled(false);
        btn_pushRebates.setBackgroundResource(R.mipmap.rwxq_cfk_no);
        btn_pushRebates.setEnabled(false);
        btn_shouHuo.setBackgroundResource(R.mipmap.rwxq_qsh);
        btn_shouHuo.setEnabled(true);
        taskShipMentsInfo = (TaskShipMentsInfo) args.getSerializable("info");
        orderid = taskShipMentsInfo.getOrderid();
        selectDianfuTwo();
        selectDianfuThree();
        tv_taskId.setText(taskShipMentsInfo.getOrderid());
        tv_buyerId.setText(taskShipMentsInfo.getAccount());
        tv_sellerId.setText("商家ID:" + taskShipMentsInfo.getUserId());
        tv_backType.setText(taskShipMentsInfo.getBackName());
        tv_cJPrice.setText(taskShipMentsInfo.getPrice());
        tv_num.setText(taskShipMentsInfo.getNumber() + "件");
        tv_time.setText(DateUtils.getDateToStringSec(taskShipMentsInfo.getAddTime()));
        tv_price.setText(taskShipMentsInfo.getMobilePrice());
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + taskShipMentsInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_taskState.setText("任务状态：待评价");
        tv_state.setText("已完成");
        tv_sellerState.setText("已完成");
        tv_evaluationState.setText("未完成");
        tv_taskCompleteState.setText("未完成");
        if (taskShipMentsInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + taskShipMentsInfo.getRemarks());
        }
        if (TextUtils.isEmpty(taskShipMentsInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + taskShipMentsInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(taskShipMentsInfo.getBaseCmi()));
        view2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view3.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        iv_2.setImageResource(R.mipmap.rwxq_2);
        iv_3.setImageResource(R.mipmap.rwxq_3);
    }

    /**
     * 待确认
     */
    public void AllTask() {
        bt_operationTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_operationTask.setEnabled(false);
        bt_CancelTask.setBackgroundResource(R.drawable.bg_radius_btn2);
        bt_CancelTask.setEnabled(false);
        btn_pushRebates.setBackgroundResource(R.mipmap.rwxq_cfk_no);
        btn_pushRebates.setEnabled(false);
        btn_shouHuo.setBackgroundResource(R.mipmap.rwxq_qsh_no);
        btn_shouHuo.setEnabled(false);
        taskAllInfo = (TaskAllInfo) args.getSerializable("info");
        orderid = taskAllInfo.getOrderid();
        selectDianfuTwo();
        selectDianfuThree();
        selectDianfuReceive();
        tv_taskId.setText(taskAllInfo.getOrderid());
        tv_buyerId.setText(taskAllInfo.getAccount());
        tv_sellerId.setText("商家ID:" + taskAllInfo.getUserId());
        tv_backType.setText(taskAllInfo.getBackName());
        tv_cJPrice.setText(taskAllInfo.getPrice());
        tv_num.setText(taskAllInfo.getNumber() + "件");
        tv_time.setText(DateUtils.getDateToStringSec(taskAllInfo.getAddTime()));
        tv_price.setText(taskAllInfo.getMobilePrice());
        Picasso.with(getActivity()).load(ApiHttpClient.URL2 + taskAllInfo.getImages()).placeholder(
                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
        tv_taskState.setText("任务状态：待确认");
        tv_state.setText("已完成");
        tv_sellerState.setText("已完成");
        tv_evaluationState.setText("已完成");
        tv_taskCompleteState.setText("未完成");
        if (taskAllInfo.getRemarks().equals(" ")) {
            tv_sellerRequire.setText("商家要求:此商家无其他要求");
        } else {
            tv_sellerRequire.setText("商家要求:" + taskAllInfo.getRemarks());
        }
        if (TextUtils.isEmpty(taskAllInfo.getMessage())) {
            tv_message.setText("订单留言：");
        } else {
            tv_message.setText("订单留言：" + taskAllInfo.getMessage());
        }
        tv_getCommission.setText(DateUtils.formateRate(taskAllInfo.getBaseCmi()));
        view2.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view3.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        view4.setBackgroundColor(getResources().getColor(R.color.steel_blue));
        iv_2.setImageResource(R.mipmap.rwxq_2);
        iv_3.setImageResource(R.mipmap.rwxq_3);
        iv_4.setImageResource(R.mipmap.rwxq_4);
    }

    TimerTask task = new TimerTask() {
        @Override
        public void run() {

            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        date1 = df.parse(df.format(new Date()));
                        date2 = df.parse(taskTime);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    diff = (date2.getTime() - date1.getTime()) / 1000;
                    int mm = (int) diff;
                    String time = change(mm);
                    tv_countDwon.setText("提交倒计时:" + time);
                    if (diff <= 0) {
                        timer.cancel();
                        isOverTime = true;
                        //cancelTask();
                        tv_countDwon.setVisibility(View.GONE);
                    }
                }
            });
        }
    };

    /*
    * 将秒数转为时分秒
    * */

    public String change(int second) {
        int h = 0;
        int d = 0;
        int s = 0;
        String hour = null;
        String minute = null;
        String sec = null;
        String m = "0";
        int temp = second % 3600;
        if (second > 3600) {
            h = second / 3600;
            if (temp != 0) {
                if (temp > 60) {
                    d = temp / 60;
                    if (d < 10) {
                        minute = "0" + d;
                    } else {
                        minute = String.valueOf(d);
                    }
                    if (temp % 60 != 0) {
                        s = temp % 60;
                        if (s < 10) {
                            sec = "0" + s;
                        } else {
                            sec = String.valueOf(s);
                        }
                    }
                } else {
                    s = temp;
                    if (s < 10) {
                        sec = "0" + s;
                    } else {
                        sec = String.valueOf(s);
                    }
                }
            }
        } else {
            d = second / 60;
            if (d < 10) {
                minute = "0" + d;
            } else {
                minute = String.valueOf(d);
            }
            if (second % 60 != 0) {
                s = second % 60;
                if (s < 10) {
                    sec = "0" + s;
                } else {
                    sec = String.valueOf(s);
                }
            }
        }
        return "0" + h + ":" + minute + ":" + sec + "";
    }

    @Override
    public boolean onBackPressed() {
        Bundle args = new Bundle();
        if (state.equals("operate")) {
            args.putString("way", "1");
            UIHelper.showAdvancesUnComplate(mActivity, args);
        } else if (state.equals("rebates")) {
            args.putString("way", "2");
            UIHelper.showAdvancesUnComplate(mActivity, args);
        } else if (state.equals("shipments")) {
            args.putString("way", "3");
            UIHelper.showAdvancesUnComplate(mActivity, args);
        } else if (state.equals("allTask")) {
            args.putString("way", "4");
            UIHelper.showAdvancesUnComplate(mActivity, args);
        } else if (state.equals("AdvancesComplate")) {
            UIHelper.showAdvancesComplate(mActivity);
        }
        finish();
        return true;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        timer.cancel();
    }
    private void getBankInfo() {
        ApiHttpClient.getBuyerBankInfo(this, userInfo.getWebzzCmsBuyerInfo().getUserid(),
                new JsonCallback<BankInfo>(BankInfo.class) {
                    @Override
                    public void onBefore(Request request) {
                        super.onBefore(request);
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        toast("网络异常,请稍后重试");
                    }

                    @Override
                    public void onResponse(ResponseInfo<BankInfo> response) {
                        int code = response.getCode();
                        String message = response.getMessage();
                        if (code == 1) {
                            showWarnDialog(message);
                            return;
                        }
                        List<BankInfo> data = response.getData();
                        if (null == data || data.size() == 0) {
                            return;
                        }
                        tv_rebatesAccount.setText(data.get(0).getAccount());
                    }

                    @Override
                    public void onAfter() {
                        super.onAfter();
                    }
                }
        );
    }

    private void selectDianfuTwo() {
        ApiHttpClient.selectDianFuTwo(this, orderid,
                new JsonCallback<SeclectDianFuTwoInfo>(SeclectDianFuTwoInfo.class) {

                    @Override
                    public void onBefore(Request request) {
                        super.onBefore(request);
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        toast("网络连接失败,请重试");
                    }

                    @Override
                    public void onResponse(ResponseInfo<SeclectDianFuTwoInfo> response) {
                        int code = response.getCode();
                        String message = response.getMessage();
                        if (code == 1) {
                            showWarnDialog(message);
                            return;
                        }

                        List<SeclectDianFuTwoInfo> seclectDianFuTwoInfos = response.getData();
                        if (null == seclectDianFuTwoInfos || seclectDianFuTwoInfos.size() == 0) {
                            return;
                        }
                        //货比三家
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageSearchResult()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv1);
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageGoods1()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv2);
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageGoods2()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv3);
                        //店铺浏览
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageIngoods1()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv4);
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageIngoods2()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv5);
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageIngoodsHeader()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv6);
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageIngoodsFooter()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv7);
                        System.out.println("tupian"+seclectDianFuTwoInfos.get(0).getImageFujia1Header());
                        if (!TextUtils.isEmpty(seclectDianFuTwoInfos.get(0).getImageFujia1Header())) {
                            view_FuJia.setVisibility(View.VISIBLE);
                            iv10.setVisibility(View.VISIBLE);
                            iv11.setVisibility(View.VISIBLE);
                            Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageFujia1Header()).placeholder(
                                    R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv10);
                            Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageFujia1Footer()).placeholder(
                                    R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv11);
                        }
                        if (!TextUtils.isEmpty(seclectDianFuTwoInfos.get(0).getImageFujia2Header())) {
                            iv12.setVisibility(View.VISIBLE);
                            iv13.setVisibility(View.VISIBLE);
                            Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageFujia2Header()).placeholder(
                                    R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv12);
                            Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageFujia2Footer()).placeholder(
                                    R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv13);
                        }
                        //聊天下单
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImageChat()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv8);
                        Picasso.with(mActivity).load(seclectDianFuTwoInfos.get(0).getImagePayment()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv9);

                    }

                    @Override
                    public void onAfter() {
                        super.onAfter();
                    }
                }
        );
    }

    private void selectDianfuThree() {
        ApiHttpClient.selectDianFuThree(this, orderid,
                new JsonCallback<SeclectDianFuThreeInfo>(SeclectDianFuThreeInfo.class) {

                    @Override
                    public void onBefore(Request request) {
                        super.onBefore(request);
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        toast("网络连接失败,请重试");
                    }

                    @Override
                    public void onResponse(ResponseInfo<SeclectDianFuThreeInfo> response) {
                        int code = response.getCode();
                        String message = response.getMessage();
                        if (code == 1) {
                            showWarnDialog(message);
                            return;
                        }
                        List<SeclectDianFuThreeInfo> seclectDianFuThreeInfos = response.getData();
                        if (null == seclectDianFuThreeInfos || seclectDianFuThreeInfos.size() == 0) {
                            return;
                        }
                        tv_rebatesMoney.setText(seclectDianFuThreeInfos.get(0).getPayPrice());
                    }

                    @Override
                    public void onAfter() {
                        super.onAfter();
                    }
                }
        );
    }

    private void selectDianfuReceive() {
        ApiHttpClient.selectDianFuReceive(this, orderid,
                new JsonCallback<SeclectDianFuReceiveInfo>(SeclectDianFuReceiveInfo.class) {
                    @Override
                    public void onBefore(Request request) {
                        super.onBefore(request);
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        toast("网络连接失败,请重试");
                    }

                    @Override
                    public void onResponse(ResponseInfo<SeclectDianFuReceiveInfo> response) {
                        int code = response.getCode();
                        String message = response.getMessage();
                        if (code == 1) {
                            showWarnDialog(message);
                            return;
                        }

                        List<SeclectDianFuReceiveInfo> seclectDianFuReceiveInfos = response.getData();
                        if (null == seclectDianFuReceiveInfos || seclectDianFuReceiveInfos.size() == 0) {
                            return;
                        }
                        Picasso.with(mActivity).load(seclectDianFuReceiveInfos.get(0).getImageRated()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_evaluation1);
                        Picasso.with(mActivity).load(seclectDianFuReceiveInfos.get(0).getImageReceive()).placeholder(
                                R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_evaluation2);

                    }

                    @Override
                    public void onAfter() {
                        super.onAfter();
                    }
                }
        );
    }
}
